package com.tigercel.xiangchengyun.ui.fragments

import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.tigercel.xiangchengyun.R
import com.tigercel.xiangchengyun.adapter.NewsBannerAdapter
import com.tigercel.xiangchengyun.entity.Banner
import com.tigercel.xiangchengyun.ui.custom.lbanners.LMBanners
import com.tigercel.xiangchengyun.ui.custom.lbanners.transformer.TransitionEffect
import kotlinx.android.synthetic.main.fragment_news_special.*

class NewsSpecialFragment : Fragment() {
    companion object {

        fun newInstance(channelPosition: Int): NewsSpecialFragment? {
            val fragment = NewsSpecialFragment()
            val bundle = Bundle()
            bundle.putInt("channelPosition", channelPosition)
            fragment.arguments = bundle
            return fragment
        }
    }

    private var containerView: View? = null
    private var banner: LMBanners<Any>? = null
    private var headBanner: View? = null
    private var channelPosition: Int = 0


    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
        containerView = inflater.inflate(R.layout.fragment_news_special, container, false)
        if (arguments != null)
            channelPosition = arguments!!.getInt("channelPosition")
//        Log.e("id编号2", channelPosition.toString())
        return containerView
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        recyclerview.layoutManager = LinearLayoutManager(activity)
//        var news1 = NewsBean("", 1, "习近平:吹响建设科技强国号角国号角国号角", "新华网", "www.baidu.com", "6小时前", 0, listOf(), 100)
//        var news2 = NewsBean("", 1, "李志强到我市调研工作", "央视新闻", "www.google.com", "7小时前", 0, listOf(), 200)
//        var news3 = NewsBean("", 1, "改善人民居住环境", "大和网", "www.9527.com", "8小时前", 0, listOf(), 10)
//        var news4 = NewsBean("", 1, "扶贫车间搭建就业脱贫", "人民日报", "www.hahah.com", "9小时前", 0, listOf(), 88)
//        var news5 = NewsBean("", 1, "非法集资案高发", "项城云", "www.eeeeeee.com", "10小时前", 0, listOf(), 999)
//
//        recyclerview.adapter = NewsSpecialAdapter(listOf(news1, news2, news3, news4, news5)) {
//            toast(it.url)
//        }
        headBanner = View.inflate(activity, R.layout.banners, null)
        banner = headBanner?.findViewById(R.id.banners)
        banner!!.setIndicatorBottomPadding(8)
        banner!!.setHoriZontalTransitionEffect(TransitionEffect.Default)
        var bannerBean = Banner(0,"","https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1522765537318&di=d6ffbf06f8204eb28510cbc8784918c7&imgtype=0&src=http%3A%2F%2Fi1.hdslb.com%2Fbfs%2Farchive%2Ffbfc3e13a06f6581629970417c0d8ec5286ddfeb.jpg","")
        var bannerBean2 = Banner(0,"","https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1522765809166&di=17b19b778ab60b9d3b214b5c3a256ea0&imgtype=0&src=http%3A%2F%2Fp3.ifengimg.com%2Fa%2F2017_29%2F4f0ea37d91daa59_size103_w1600_h1000.jpg","")
        var bannerBean3 = Banner(0,"","https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1523360415&di=b483f5dab40ad6c0450110601af6dbde&imgtype=jpg&er=1&src=http%3A%2F%2Fi0.hdslb.com%2Fbfs%2Farchive%2F64222c045288c88d83cebb57ee71c5bb25780742.jpg","")
        banner!!.setAdapter(NewsBannerAdapter(activity),listOf(bannerBean,bannerBean2,bannerBean3))
        recyclerview.addHeaderView(headBanner)
    }

    override fun onDestroy() {
        super.onDestroy()
        banner!!.clearImageTimerTask()
    }
}
